﻿using System;

namespace xrwang.DDNS
{
    /// <summary>
    ///ActionResult：执行动作的结果
    /// </summary>
    public class ActionResult
    {
        //属性
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="message">消息</param>
        public ActionResult(bool success, string message)
        {
            Success = success;
            Message = message;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        public ActionResult(bool success)
            : this(success, "")
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="result">动作结果对象</param>
        public ActionResult(ActionResult result)
            : this(result.Success, result.Message)
        {
        }

        /// <summary>
        /// 返回字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("结果：{0}\r\n消息：{1}", Success, Message);
        }
    }

    /// <summary>
    /// 指定动作的结果，并附带数据
    /// </summary>
    /// <typeparam name="T">附带数据的类型</typeparam>
    public class ActionResult<T> : ActionResult
    {
        //属性
        /// <summary>
        /// 附带的数据
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="message">消息</param>
        /// <param name="data">数据</param>
        public ActionResult(bool success, string message, T data)
            : base(success, message)
        {
            Data = data;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="message">消息</param>
        public ActionResult(bool success, string message)
            : this(success, message, default(T))
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        public ActionResult(bool success)
            : this(success, string.Empty, default(T))
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="result">动作结果对象</param>
        public ActionResult(ActionResult result)
            : this(result.Success, result.Message, default(T))
        { }

        /// <summary>
        /// 返回字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0}\r\n数据：{1}", base.ToString(), Data);
        }
    }

    /// <summary>
    /// 指定动作的结果，并附带两个数据
    /// </summary>
    /// <typeparam name="T1">附带数据1的类型</typeparam>
    /// <typeparam name="T2">附带数据2的类型</typeparam>
    public class ActionResult<T1, T2> : ActionResult
    {
        //属性
        /// <summary>
        /// 附带的数据1
        /// </summary>
        public T1 Data1 { get; set; }
        /// <summary>
        /// 附带的数据2
        /// </summary>
        public T2 Data2 { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="message">消息</param>
        /// <param name="data1">数据1</param>
        /// <param name="data2">数据2</param>
        public ActionResult(bool success, string message, T1 data1, T2 data2)
            : base(success, message)
        {
            Data1 = data1;
            Data2 = data2;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="message">消息</param>
        public ActionResult(bool success, string message)
            : this(success, message, default(T1), default(T2))
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        public ActionResult(bool success)
            : this(success, string.Empty, default(T1), default(T2))
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="result">动作结果对象</param>
        public ActionResult(ActionResult result)
            : this(result.Success, result.Message, default(T1), default(T2))
        { }

        /// <summary>
        /// 返回字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0}\r\n数据1：{1}\r\n数据2：{2}", base.ToString(), Data1, Data2);
        }
    }

    /// <summary>
    /// 指定动作的结果，并附带三个数据
    /// </summary>
    /// <typeparam name="T1">附带数据1的类型</typeparam>
    /// <typeparam name="T2">附带数据2的类型</typeparam>
    /// <typeparam name="T3">附带数据3的类型</typeparam>
    public class ActionResult<T1, T2, T3> : ActionResult
    {
        //属性
        /// <summary>
        /// 附带的数据1
        /// </summary>
        public T1 Data1 { get; set; }
        /// <summary>
        /// 附带的数据2
        /// </summary>
        public T2 Data2 { get; set; }
        /// <summary>
        /// 附带的数据3
        /// </summary>
        public T3 Data3 { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="message">消息</param>
        /// <param name="data1">数据1</param>
        /// <param name="data2">数据2</param>
        /// <param name="data3">数据3</param>
        public ActionResult(bool success, string message, T1 data1, T2 data2, T3 data3)
            : base(success, message)
        {
            Data1 = data1;
            Data2 = data2;
            Data3 = data3;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="message">消息</param>
        public ActionResult(bool success, string message)
            : this(success, message, default(T1), default(T2), default(T3))
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="success">是否成功</param>
        public ActionResult(bool success)
            : this(success, string.Empty, default(T1), default(T2), default(T3))
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="result">动作结果对象</param>
        public ActionResult(ActionResult result)
            : this(result.Success, result.Message, default(T1), default(T2), default(T3))
        { }

        /// <summary>
        /// 返回字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0}\r\n数据1：{1}\r\n数据2：{2}\r\n数据3：{3}", base.ToString(), Data1, Data2, Data3);
        }
    }
}